<?php


namespace EchoPHP\Console;

use EchoPHP\Foundation\Container;
use Symfony\Component\Console\Application as SymfonyApplication;
use Symfony\Component\Console\Input\InputOption;

class Application extends SymfonyApplication {

    protected $container;

    public function __construct(Container $container, $version) {
        $this->container = $container;
        parent::__construct('EchoPHP Framework', $version);
    }

    /**
     * 注册命令行脚本
     * @param $command
     * @return \Symfony\Component\Console\Command\Command|null
     * @throws \Exception
     */
    public function resolve($command) {
        $command = $this->container->make($command);
        if ($command instanceof Command) {
            $command->setContainer($this->container);
        }
        return $this->add($command);
    }

    /**
     * 添加默认选项
     */
    public function addDefaultOptions() {
        $this->getDefinition()->addOptions([
            new InputOption('--xhprof', '-X', InputOption::VALUE_NONE, '强制执行Xhprof性能分析'),
        ]);
    }


}